package com.zyhl.gmall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zyhl.gmall.common.result.Result;
import com.zyhl.gmall.model.product.BaseAttrInfo;
import com.zyhl.gmall.model.product.BaseCategory1;
import com.zyhl.gmall.product.service.BaseAttrInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/baseAttr")
public class BaseAttrInfoController {

    @Autowired
    private BaseAttrInfoService baseAttrInfoService;

    @RequestMapping("/findById")
    public Result findById(Long id){
        return Result.ok(baseAttrInfoService.findById(id));
    }

    @RequestMapping("/getList")
    public List<BaseAttrInfo> findAll(BaseAttrInfo baseAttrInfo){
        return baseAttrInfoService.findAll(baseAttrInfo);
    }

    /**
     * 新增和修改  判断新增时有没有id，如果没有则新增
     * @param baseAttrInfo
     * @return
     */
    @PostMapping("/save")
    public Result save(@RequestBody BaseAttrInfo baseAttrInfo){
        baseAttrInfoService.save(baseAttrInfo);
        return Result.ok();
    }


    @RequestMapping("delById")
    public Result delById(Long id){
        baseAttrInfoService.deleteId(id);
        return Result.ok();
    }

    /**
     * 条件+分页查询
     */
    @GetMapping("/queryPageCondition/{page}/{size}")
    public Result pageQuery(@PathVariable("page") Integer page,
                            @PathVariable("size") Integer size,
                            @RequestBody BaseAttrInfo baseAttrInfo){
        return Result.ok(baseAttrInfoService.searchByPage(page,size,baseAttrInfo));
    }

    @RequestMapping("/page/{page}/{size}")
    public Result page(@PathVariable(value = "page")Integer page,
                       @PathVariable(value = "size")Integer size){
        return Result.ok(baseAttrInfoService.page(page,size));
    }

}
